import org.apache.spark.mllib.linalg.distributed.{MatrixEntry, CoordinateMatrix}
import org.apache.spark.sql.Column
import org.apache.spark.{SparkContext, SparkConf}
import spark.udrank.StringCoordinateMatrix

import scala.collection.mutable.ArrayBuffer

/**
  * Created by root on 16-1-25.
  */
object Main {

  def main(args: Array[String]): Unit = {
    val conf = new SparkConf().setAppName("spark-partition-test").setMaster("local")
    val sc = new SparkContext(conf)
    val rdd = sc.parallelize(Array((0l,0l,1),(0l,1l,2),(1l,1l,4)))
    val blockMatrix = new CoordinateMatrix(rdd.map(x => new MatrixEntry(x._1.toLong,x._2.toLong,x._3))).toBlockMatrix(1,1)
    (blockMatrix multiply blockMatrix).toLocalMatrix().toArray.foreach(println)
    val stringCoordinateMatrix = new StringCoordinateMatrix(rdd.map(x=>(x._1.toString,x._2.toString,x._3.toDouble)))
    (stringCoordinateMatrix * stringCoordinateMatrix).value.foreach(println)
  }
}
